package genedit.model.graph.classModel;

import genedit.gui.GMainFrame;
import genedit.gui.exceptions.ElementNePostoji;
import genedit.gui.exceptions.ElementPostoji;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class GParameters implements ITableModel, Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 7939286351949099391L;
	private Map<String, GParameter> parameters = new HashMap<String, GParameter>();
	
	public void addParameter(GParameter novi) throws ElementPostoji {
		if (parameters.containsKey(novi.getName()))
			throw new ElementPostoji(GMainFrame.getInstance().getResourceBundle().getString("PostojiA"));
		parameters.put(novi.getName(), novi);
	}
	
	public void changeParameter(GParameter novi) throws ElementPostoji {
		if (!parameters.containsKey(novi.getName()))
			throw new ElementPostoji(GMainFrame.getInstance().getResourceBundle().getString("NePostojiA"));
		parameters.put(novi.getName(), novi);
	}
	
	public void removeParameter(GParameter stari) throws ElementNePostoji {
		if (!parameters.containsKey(stari.getName()))
			throw new ElementNePostoji(GMainFrame.getInstance().getResourceBundle().getString("NePostojiA"));
		parameters.remove(stari.getName());
	}
	
	public GParameter getParameter(String key) throws ElementNePostoji {
		if (!parameters.containsKey(key))
			throw new ElementNePostoji(GMainFrame.getInstance().getResourceBundle().getString("NePostojiA"));
		return parameters.get(key);
	}
	
	public Iterator<String> getParameter() {
		Set<String> names = parameters.keySet();
		return names.iterator();
	}
	
	public Set<String> getParameterKeys() {
		Set<String> names = parameters.keySet();
		return names;
	}

	public Map<String, GParameter> getParameters() {
		return parameters;
	}

	public void setParameters(Map<String, GParameter> parameters) {
		this.parameters = parameters;
	}

	@Override
	public int getRowCount() {
		return parameters.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		ArrayList<GParameter> pameters = new ArrayList<GParameter>(parameters.values());
		switch(columnIndex){
			case 0: return pameters.get(rowIndex).getType();
			case 1: return pameters.get(rowIndex).getName();
		}
		return "";
	}

}
